package C_Paper;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @Auther: zzx
 * @Date: 2024.04.24/4/2
 */
public class C100_1 {
    //https://blog.csdn.net/2301_76848549/article/details/134622198?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171206852016800182741014%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=171206852016800182741014&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-134622198-null-null.142^v100^control&utm_term=%E5%8D%8E%E4%B8%BAod%E9%A2%98%E5%BA%93
    //https://blog.csdn.net/qfc_128220/article/details/127914382?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171247431016800188516706%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=171247431016800188516706&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-127914382-null-null.142^v100^pc_search_result_base1&utm_term=%E5%8D%8E%E4%B8%BAod%E6%9C%BA%E8%AF%95&spm=1018.2226.3001.4187
    //身高差
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int n = sc.nextInt();
        Integer[] m = new Integer[n];
        for (int i = 0; i < n; i++) {
            m[i] = sc.nextInt();
        }
        Arrays.sort(m, Comparator.comparing(a -> Math.abs(a - x)));
        System.out.println(Arrays.toString(m));
    }
}
